home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0017_ZTRAS.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  147 lines

  1. Unit Globals;
  2.  
  3. Interface
  4.  
  5. Uses Crt{, Dos?};
  6.  
  7. { Special keyboard Characters: }
  8. { I've squeezed them into a couple of lines so that they'd fit in a
  9. message.. might be an idea to expand them back to ~20 lines or so..}
  10.  
  11.       NULL = #0;    BS = #8;    ForMFEED = #12;    CR = #13;    ESC = #27;
  12.  
  13.       HOMEKEY = #199;    {Values apply if only used With the 'Getkey' Function}
  14.       endKEY = #207;      UPKEY = #200;      doWNKEY = #208;
  15.       PGUPKEY = #201;     PGDNKEY = #209;    LEFTKEY = #203;
  16.       inSKEY = #210;      RIGHTKEY = #205;   DELKEY = #211;
  17.       CTRLLEFTKEY = #243; CTRLRIGHTKEY = #244;
  18.       F1 = #187;    F2 = #188;    F3 = #189;    F4 = #190;    F5  = #191;
  19.       F6 = #192;    F7 = #193;    F8 = #194;    F9 = #195;    F10 = #196;
  20.  
  21. Type  CurType       = ( off, Big, Small );
  22.  
  23. Var   Ins           : Boolean;  { Global Var containing status of Insert key}
  24.  
  25. {-----------------------------------------------------------------------------}
  26. Function  GetKey : Char;
  27. Procedure EdReadln(Var S : String);
  28.  
  29. Procedure Cursor( Size : CurType ); { Either off, Big or Small }
  30. Procedure ChangeCursor( Ins : Boolean );
  31.  
  32. {-----------------------------------------------------------------------------}
  33. Implementation
  34.  
  35. Function GetKey; { : Char; }
  36.  
  37. Var C : Char;
  38.  
  39. begin
  40.   C := ReadKey;
  41.   Repeat
  42.     if C = NULL then
  43.     begin
  44.       C := ReadKey;
  45.       if ord(C) > 127 then
  46.         C := NULL
  47.       else
  48.         GetKey := Chr(ord(C) + 128);
  49.     end else GetKey := C;
  50.   Until C <> NULL;
  51. end; { GetKey }
  52.  
  53. {-----------------------------------------------------------------------------}
  54. Procedure EdReadln; { (Var S : String); }
  55.  
  56. { Legal : IString; MaxLength : Word; Var ESCPressed : Boolean); }
  57.  
  58. Var CPos : Word;
  59.     Ch   : Char;
  60.     OldY : Byte;
  61.  
  62.     Legal      : String[1];
  63.     MaxLength  : Byte;
  64.     EscPressed : Boolean;
  65.  
  66. begin
  67.   OldY := WhereY - 1;
  68.   ChangeCursor(Ins);
  69.   CPos := 1;                {Place cursor at START of line}
  70. { CPos := Succ(Length(S));} {Whereas this places cursor at end of line}
  71.   Legal := '';              {Legal and Maxlength originally passed as params}
  72.   MaxLength := Lo( WindMax ) - Lo( WindMin );
  73.  
  74.   Repeat
  75.     Cursor( off );
  76.     GotoXY(1, WhereY);
  77.     Write(S, '':(MaxLength - Length(S)));
  78.     GotoXY(CPos, WhereY);
  79.     ChangeCursor(Ins);
  80.     Ch := GetKey;
  81.     Case Ch of
  82.       HOMEKEY  : CPos := 1;
  83.       endKEY   : CPos := Succ(Length(S));
  84.       inSKEY   : begin
  85.                     Ins := not Ins;
  86.                     ChangeCursor(Ins);
  87.                  end;
  88.       LEFTKEY  : if CPos > 1 then Dec(CPos);
  89.       RIGHTKEY : if CPos <= Length(S) then Inc(CPos);
  90.       BS       : if CPos > 1 then
  91.                  begin
  92.                     Delete(S, Pred(CPos), 1);
  93.                     Dec(CPos);
  94.                  end;
  95.       DELKEY   : if CPos <= Length(S) then Delete(S, CPos, 1);
  96.       CR       : ;
  97.       ESC      : begin
  98.                     S := '';
  99.                     CPos := 1;
  100.                  end;
  101.       else
  102.       begin
  103.         if ((Legal = '') or (Pos(Ch, Legal) <> 0)) and
  104.            ((Ch >= ' ') and (Ch <= '~')) and
  105.             (Length(S) < MaxLength) then
  106.         begin
  107.           if Ins then Insert(Ch, S, CPos) else
  108.           if CPos > Length(S) then S := S + Ch else
  109.              S[CPos] := Ch;
  110.           Inc(CPos);
  111.         end;
  112.       end;
  113.     end; { Case }
  114.   Until (Ch = CR);
  115.   Cursor( Small );
  116.   ESCPressed := Ch <> ESC;
  117.   Writeln;
  118. end; { EditString }
  119.  
  120. {-----------------------------------------------------------------------------}
  121. Procedure Cursor; { ( Size : CurType ); { Either off, Big or Small }
  122.  
  123. Var Regs : Registers;
  124.  
  125. begin
  126.    With Regs Do begin
  127.       Ax := $100;
  128.       Case Size of
  129.          off   : Cx := $3030;
  130.          Big   : Cx := $0F;
  131.          Small : Cx := $607;
  132.       end;
  133.       Intr ( $10, Regs );
  134.    end;
  135. end;
  136.  
  137. {-----------------------------------------------------------------------------}
  138. Procedure ChangeCursor; { ( Ins : Boolean ); }
  139. {Changes cursor size depending on status of insert key}
  140.  
  141. begin
  142.    if Ins then Cursor( Small ) else Cursor( Big );
  143. end;
  144.  
  145. begin
  146. end.
  147.